import 'package:app_health/pages/home/HomePage.dart';
import 'package:flutter/material.dart';

class LoginPage extends StatelessWidget {

  @override
  Widget build(BuildContext context) {

    //toolbarOpacity透明度
    //elevation阴影
    return new Scaffold(
      appBar: new AppBar(
        toolbarOpacity: 0,
        elevation: 0,
        backgroundColor: Colors.transparent,
      ),
      body: new EditTextWidget(),

    );
  }
}

/**
 * 主页面
 */
class EditTextWidget extends StatefulWidget {
  @override
  State<EditTextWidget> createState() => EditTextWidgetState();
}

class EditTextWidgetState extends State<EditTextWidget> {
  final TextEditingController _getPhoneNum = new TextEditingController();
  final TextEditingController _getPassWord = new TextEditingController();

  @override
  Widget build(BuildContext context) {

    Widget ImageWidget = new Container(
      margin: const EdgeInsets.all(60.0),
      child: new Center(
        child: new Image.asset(
          'assets/images/logo.png',
          fit: BoxFit.none,
        ),
      ),
    );
    //登录静态提示文字
    Widget TipsWidget = new Container(
      margin: const EdgeInsets.fromLTRB(0, 16.0, 0, 0),
      child: new RichText(
        text: new TextSpan(
          text: '登录即表示您同意',
          style: new TextStyle(color: Colors.black, fontSize: 14.0),
          children: <TextSpan>[
            new TextSpan(
              text: '用户协议',
              style: new TextStyle(color: Color(0xFF0AD0B2), fontSize: 14.0),
            ),
          ],
        ),
      ),
    );
    //手机号输入框
    //margin，左，上，右，下，某些不支持padding要在外面套一层new Padding（）
    //new Divider()横线
    Widget PhoneNumWidget = new Container(
      margin: const EdgeInsets.fromLTRB(16.0, 10.0, 32.0, 16.0),
      child: new Column(
        children: <Widget>[
          new Row(
            children: <Widget>[
              new Padding(
                padding: EdgeInsets.fromLTRB(16, 0, 16.0, 0),
                child: new Text(
                  '手机号',
                  style: new TextStyle(color: Colors.black, fontSize: 16.0),
                ),
              ),
              new Expanded(
                child: new TextField(
                  cursorColor:  Color(0xFF0AD0B2),
                  keyboardType: TextInputType.number,
                  controller: _getPhoneNum,
                  decoration: new InputDecoration(
                    hintText: '请输入注册手机号',
                    hintStyle:
                    new TextStyle(fontSize: 14.0, color: Colors.black26),
                    border: InputBorder.none,
                  ),
                ),
              ),
            ],
          ),
          new Padding(
            padding: EdgeInsets.fromLTRB(16, 0, 0, 0),
            child: new Divider(),
          ),
        ],
      ),
    );

    //密码框
    //obscureText是否显示圆点
    Widget PassWordWidget = new Container(
      margin: const EdgeInsets.fromLTRB(16.0, 0, 32.0, 16.0),
      child: new Column(
        children: <Widget>[
          new Row(
            children: <Widget>[
              new Padding(
                padding: EdgeInsets.fromLTRB(16, 0, 32.0, 0),
                child: new Text(
                  '密码',
                  style: new TextStyle(color: Colors.black, fontSize: 16.0),
                ),
              ),
              new Expanded(
                child: new TextField(
                  cursorColor: Color(0xFF0AD0B2),
                  obscureText: true,
                  controller: _getPassWord,
                  decoration: new InputDecoration(
                    hintText: '请输入六位数密码',
                    hintStyle:
                    new TextStyle(fontSize: 14.0, color: Colors.black26),
                    border: InputBorder.none,
                  ),
                ),
              ),
            ],
          ),
          new Padding(
            padding: EdgeInsets.fromLTRB(16, 0, 0, 0),
            child: new Divider(),
          ),
        ],
      ),
    );

    //登录按钮
    //shape设置边框样式
    Widget loginButton(BuildContext context) {
      return new Container(
        width: 400.0,
        padding: EdgeInsets.fromLTRB(30.0, 15.0, 30.0, 0.0),
        child: new RaisedButton(
          shape: RoundedRectangleBorder(
            borderRadius: BorderRadius.only(
              topRight: Radius.circular(80.0),
              topLeft: Radius.circular(80.0),
              bottomRight: Radius.circular(80.0),
              bottomLeft: Radius.circular(80.0),
            ),
          ),
          color:Color(0xFF0AD0B2),
          child: new Padding(
            padding: EdgeInsets.all(10.0),
            child: new Text(
              "登录",
              style: new TextStyle(color: Colors.white, fontSize: 16.0),
            ),
          ),
          onPressed: () {
            _toRegist();
          },
        ),
      );
    }

    //组合
    return new ListView(
      children: <Widget>[
        new Column(
          children: <Widget>[
            ImageWidget,
            PhoneNumWidget,
            PassWordWidget,
            loginButton(context),
            TipsWidget,
          ],
        )
      ],
    );
  }

  //点击事件
  void _toRegist() {
    print({'手机号': _getPhoneNum.text, '密码': _getPassWord.text});
    HomePageWidget.start(context);
  }
}
